<template>
  <div class="violatePage">
    <div v-infinite-scroll="load" class="block marginT30" :infinite-scroll-disabled="loading">
      <el-timeline>
        <el-timeline-item
          v-for="(item, index) in list"
          :key="index"
          :timestamp="item.createTime"
          placement="top"
        >
          <el-card>
            <h4 class="line-height30">违规情况：{{ item.targetName }}</h4>
            <p class="line-height30">涉及内容：{{ item.targetName }}</p>
            <p class="line-height30">
              处理结果：
              <el-tag v-if="item.state === 'unprocessed'" effect="dark">未处理</el-tag>
              <el-tag v-if="item.state === 'ignore'" effect="dark">无效举报</el-tag>
              <el-tag v-if="item.state === 'warn'" effect="dark">警告</el-tag>
              <el-tag v-if="item.state === 'disable_content'" effect="dark">封禁内容</el-tag>
              <el-tag v-if="item.state === 'disable_account'" effect="dark">封号</el-tag>
              <el-tag v-if="item.state === 'enable'" effect="dark">恢复正常</el-tag>
            </p>
          </el-card>
        </el-timeline-item>
      </el-timeline>
    </div>
  </div>
</template>

<script>
import { violatePage } from '@/api/users';

export default {
  name: 'ViolatePage',
  data () {
    return {
      loading: false,
      listQuery: {
        condition: this.$route.query.param,
        pager: {
          page: 1,
          pageSize: 10
        }
      },
      list: [],
      total: null
    };
  },
  computed: {

  },
  watch: {},
  created () {
    this.init();
  },
  methods: {
    load () {
      if (this.list.length < this.total) {
        this.listQuery.pager.page += 1;
        this.getViolatePage();
      }
    },

    // 用于初始化数据
    async init () {
      await this.getViolatePage();
    },

    // 违规
    getViolatePage () {
      this.loading = true;
      violatePage(this.listQuery)
        .then(res => {
          // console.log('违规:', res.data);
          this.list = this.list.concat(res.data.records);
          this.total = res.data.total;
          this.loading = false;
        })
        .catch(error => {
          this.loading = false;
        });
    }
  }
};
</script>

<style lang="scss" scoped></style>
